import request from '@/utils/request'

// 查询设备列表
export function listEquipment(query) {
  // 确保分页参数存在
  if (!query.pageSize) {
    query.pageSize = 20;
  }
  if (!query.pageNum) {
    query.pageNum = 1;
  }
  
  return request({
    url: '/ldzl-sb/sb/equipment/list',
    method: 'get',
    params: query
  })
}

// 查询设备详细信息
export function getEquipment(equipmentId) {
  return request({
    url: '/ldzl-sb/sb/equipment/' + equipmentId,
    method: 'get'
  })
}

// 新增设备
export function addEquipment(data) {
  return request({
    url: '/ldzl-sb/sb/equipment',
    method: 'post',
    data: data
  })
}

// 修改设备
export function updateEquipment(data) {
  return request({
    url: '/ldzl-sb/sb/equipment',
    method: 'put',
    data: data
  })
}

// 删除设备
export function delEquipment(equipmentIds) {
  return request({
    url: '/ldzl-sb/sb/equipment/' + equipmentIds,
    method: 'delete'
  })
}

// 生成设备编码
export function generateEquipmentCode(type) {
  return request({
    url: '/ldzl-sb/sb/equipment/generate/code/' + type,
    method: 'get'
  })
}

// 更新设备状态
export function updateEquipmentStatus(equipmentId, status, reason) {
  const data = {
    equipmentId: equipmentId,
    status: status,
    reason: reason
  }
  return request({
    url: '/ldzl-sb/sb/equipment/status',
    method: 'put',
    data: data
  })
}

// 获取设备状态统计
export function getEquipmentStatusStats() {
  return request({
    url: '/ldzl-sb/sb/equipment/status/stats',
    method: 'get'
  })
} 